<extend name="_layout/main"/>
<block name="head">
    <style>
        #main {
            margin-top: 1.5rem;
        }

    </style>
</block>
<block name="top">
    <header class="mui-bar mui-bar-nav report-header box-s" id="header">
        <a href="javascript:history.go(-1)"><i class="iconfont icon-fanhui fl"></i></a>
        <p>管理收货地址</p>
    </header>
</block>

<block name="content">
    <div id="main" class="mui-clearfix contaniner">
        <volist name="address" id="item">
            <div class="addlist clearfloat">
                <div class="top clearfloat box-s">
                    <ul>
                        <li>
                            <span class="fl">{$item.name}</span>
                            <span class="fr">{$item.mobile}</span>
                        </li>
                        <li>
                            {$item.province} {$item.city} {$item.area} {$item.address|stripslashes}
                        </li>
                    </ul>
                </div>
                <div class="bottom clearfloat box-s">
                    <section class="shopcar clearfloat">
                        <div class="radio fl">
                            <label>
                                <input type="radio" class="set_default" name="is_default" data-id="{$item.id}" value="1"
                                <eq name="item.is_default" value="1">checked="checked"</eq>
                                >
                                <div class="option"></div>
                                <span class="mradd smradd fl">默认</span>
                            </label>
                        </div>

                        <div class="right fr clearfloat">
                            <a href="{:U('delete', ['id'=>$item['id']])}" class="fr" id="btn-del">
                                <i class="iconfont icon-lajixiang"></i>
                                删除
                            </a>
                        </div>
                    </section>
                </div>
            </div>
        </volist>

    </div>

    <a href="{:U('add')}" class="address-add fl">
        添加新地址
    </a>
</block>
<block name="scripts">
    <script>
        $(document).on('click', '#btn-del', function (e) {
            e.preventDefault();
            var _this = $(this);
            var url = _this.attr('href');
            if (!url || url == '') {
                return;
            }
            mui.confirm('确认删除该地址吗？', '提示', ['确定', '取消'], function (obj) {
                if (obj.index == 0) {
                    $.get(url, {}, function (xdata) {
                        mui.alert(xdata.message);
                        if (xdata.status == 'success') {
                            setTimeout(function () {
                                _this.parent().parent().parent().parent().remove();
                            }, 500);
                        }
                    }, 'json')
                }
            });

        })

        $(document).on('click', '.set_default', function (e) {
            var id = $(this).data('id');
            if (isNaN(id) || id == '') {
                return;
            }

            $.post("{:U('set_default')}", {id: id}, function (xdata) {
//                if(xdata.status == 'success'){
                    mui.toast(xdata.message);
//                }
            }, 'json');
        })
    </script>
</block>